package cn.wolfcode.wms.domain;

import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class Employee extends BaseDomain {

    private String name;
    private String password;
    private String email;
    private Integer age;
    private boolean admin;
    private Department dept;
    private List<Role> roles = new ArrayList<>();

    public String getRoleNames() {
        // 1. 如果是超级管理员，直接返回
        if (this.admin) {
            return "[超级管理员]";
        }

        List<Role> roles = this.getRoles();
        if (roles.size() == 0) {
            return "[平民]";
        }

        // 如果没有角色
        StringBuilder sb = new StringBuilder(50);
        sb.append("[");

        // 2. 如果是其他角色
        for (Role role : roles) {
            sb.append(role.getName()).append(",");
        }
        // 3. 替换最后一个，为]
        sb.deleteCharAt(sb.length()-1);
        sb.append("]");
        return sb.toString();
    }
}